using Godot;
using System;

public partial class MyRigidBody2d : RigidBody2D
{
	Boolean isGroud = false;

	// Called when the node enters the scene tree for the first time.
	public override void _Ready()
	{
		// 旋转锁定
		this.LockRotation = true;
		// 开启碰撞需要设置下面两个属性
		this.ContactMonitor = true;
		this.MaxContactsReported = 1;
	}

	public override void _PhysicsProcess(double delta)
	{
		base._PhysicsProcess(delta);
		// 通过水平轴控制左右移动
		float horizontal = Input.GetAxis("左","右");
		// 速度
		this.LinearVelocity = new Vector2(horizontal * 100,this.LinearVelocity.Y);
		// 跳跃
		if (isGroud && Input.IsActionJustPressed("跳跃"))
		{
			this.LinearVelocity = new Vector2(this.LinearVelocity.X, -300);
		}
	}

	// 碰撞检测
	public void bodyEnter(Node body)
	{
		isGroud = true;
	}

	public void bodyExit(Node body)
	{
		isGroud = false;
	}

}
